<?php
/**
 * Enter description here...
 *
 */
class GeneralComponent extends Object {
    var $components = array('Readini');
	
    /**
     * Startup - Link the component to the controller.
     *
     * @param controller
     */
    
    function startup(&$controller)
    {
		//$this->controller =& $controller;    	
    }
	
	function toYMDDate($mdyDate)
    {
        $mdyDate = explode("-",$mdyDate);
        krsort($mdyDate);
        return  implode("/",$mdyDate);
    }
    
	function toDMYDate($mdyDate)
    {
    	$mdyDate = explode("-",$mdyDate);
        krsort($mdyDate);   
        return  implode("/",$mdyDate);
    }

    
    function getListSize()
    {
    	//Get data from file config
    	$data = $this->getDataFromConfigFile('image.ini');
		
		//Get small size
		$result[] = "Cỡ nhỏ ({$data['SmallSize']['width']}x{$data['SmallSize']['height']})";
		 //Get medium size
		$result[] = "Cỡ trung bình({$data['MediumSize']['width']}x{$data['MediumSize']['height']})";
		 //Get large size
		$result[] = "Cỡ lớn({$data['LargeSize']['width']}x{$data['LargeSize']['height']})";
		
		return $result;
    }
  	
    
    function getListThumbSize()
    {
    	//Get data from file config
    	$data = $this->getDataFromConfigFile('image.ini');
		
		//Get small size
		$result[] = "Cỡ nhỏ ({$data['ThumbSmallSize']['width']}x{$data['ThumbSmallSize']['height']})";
		 //Get medium size
		$result[] = "Cỡ trung bình({$data['ThumbMediumSize']['width']}x{$data['ThumbMediumSize']['height']})";
		 //Get large size
		$result[] = "Cỡ lớn({$data['ThumbLargeSize']['width']}x{$data['ThumbLargeSize']['height']})";
		
		return $result;
    }
    
    function getSize($option = 1)
    {
    	switch ($option)
    	{
    		case 1:
    			$result = $this->getHeightWidthSize('MediumSize');
    			break;
    		case 2:
    			$result = $this->getHeightWidthSize('LargeSize');
    			break;
    		default:
    			$result = $this->getHeightWidthSize('SmallSize');
    			break;
    	}
    	return $result;
    }
    
    function getThumbSize($option = 1)
    {
    	switch ($option)
    	{
    		case 1:
    			$result = $this->getHeightWidthSize('ThumbMediumSize');
    			break;
    		case 2:
    			$result = $this->getHeightWidthSize('ThumbLargeSize');
    			break;
    		default:
    			$result = $this->getHeightWidthSize('ThumbSmallSize');
    			break;
    	}
    	return $result;
    }
    
    function getHeightWidthSize($typename = null)
    {
    	//Get data from file config
    	$data = $this->getDataFromConfigFile('image.ini');
    	$result['Size'] = $data[$typename];
    	return $result;
    }
    
    
    function getDataFromConfigFile($filename = "common.ini")
    {
    	//Read file config
		$fullPathName = WWW_ROOT . 'config/'.$filename;
		$data = $this->Readini->read($fullPathName);
		return $data;
    }
    
	/**
	 * @name infoFile
	 * @param $filename
	 * @param $folderContain
	 * @return array $info: file information
	 */
	function infoFile($filename = null, $folderContain = 'files')
	{
		$file = new File(APP.WEBROOT_DIR.DS.$folderContain.DS.$filename);
    	$info = $file->info();
    	$info['last_changed'] = $file->lastChange();
    	$info['size'] = $file->size();
		return $info;
	}
	
	
  }
	
?>